<template>
  <div id="complainTopSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item prop="createTime" label="投诉时间:">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            class="datetimerange"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="处理状态" prop="processStatu">
          <el-select v-model="formInline.processStatu" clearable>
            <el-option
              v-for="item in processStatusList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否有效" prop="complainStatu">
          <el-select v-model="formInline.complainStatu" clearable>
            <el-option
              v-for="item in effectiveList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="投诉人大鹏号:" prop="dpAccount">
          <el-input
            clearable
            v-model="formInline.dpAccount"
            placeholder="请输入大鹏号"
          ></el-input>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch">
            搜索
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  props: {
    formInline: {
      type: Object,
      default: () => {
        return {
          createTime: '',
          processStatu: '', // 处理状态
          complainStatu: '', // 是否有效
          dpAccount: '',
          startTime: '',
          endTime: ''
        }
      }
    }
  },
  data() {
    return {
      processStatusList: [{ dictLabel: '全部', dictValue: '' }],
      effectiveList: [{ dictLabel: '全部', dictValue: '' }]
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  },
  mounted() {
    this.getTopSearch()
  },
  methods: {
    async getTopSearch() {
      let processStatusList = await sysNormalDisable('complain_process_state')
      this.processStatusList = this.processStatusList.concat(processStatusList)
      let effectiveList = await sysNormalDisable('complain_complaint_state')
      this.effectiveList = this.effectiveList.concat(effectiveList)
    },
    toSearch() {
      this.$emit('toSearch')
    },
    reset() {
      this.$refs.ruleForm.resetFields()
    }
  }
}
</script>
<style lang="less"></style>
